<?php
// avoid excuted from web[http://].
if(isset($_SERVER['REQUEST_METHOD'])){
    echo "<html><body>Permission denied.</body></html>\n";
    exit();
}
require_once (dirname(__FILE__) . '/../../../../inc/class/init.php');
WF::initCLI($argv, $argc);
//create object WFExitCode and include_file /path/to/ExitCode.php
$objExitCode = WF::getConfigFactory()->getExitCode();
$file_interface = basename(__FILE__);
/*
 * php.exe
 * synWidgetXMLToDB.php $argv[0]
 * ...
 * 
 */
if($argc < 1){
    $objExitCode->exitCli(WFExitCode::ERROR_WRONG_PARAMETER, $file_interface);
}else if((isset($argv[1]) && in_array($argv[1], array('--help', '-help', '-h', '-?')))){
    $objExitCode->exitCli(WFExitCode::SHOW_HELP, $file_interface);
}else{
    try{
        WF::getDataObject()->beginTransaction();
        WF::getWidgetFactory()->getInterface()->synWidgetComponentXMLToDB();
        WF::getDataObject()->commit();
        $objExitCode->exitCli(WFExitCode::SUCCESS);
    }catch(Exception $e){
        WF::getDataObject()->rollBack();
        $msg = $e->getMessage();
        myerror_log($msg);
        $objExitCode->exitCli(WFExitCode::ERROR_SYN_COMPONENTXMLTODB, null, $msg);
    }
}